<?php
/**
 * Follow manage all action of follower and folling 
 * 
 * 
 */
class FollowHelper extends Helper{
	
	/**
	 * include necessary helper
	 * 
	 */
	public $helpers = array( 'Html', 'Js' );
	
	/**
	 * Check following status
	 *
	 * @param boolean $status: if $status = true follow already
	 * 	otherwise not yet follow
	 */
	
	public function following( $status, $user_id, $username ){
		
		if( $status == true ){
			return $this->unfollow($user_id, $username);
		}else{
			//return $this->Html->tag('button',$this->Html->tag( 'span', __('Follow', true)), array('href' => '/friends/follow'));
			return $this->Js->link(
				$this->Html->tag( 'span', __('Follow', true)), 
				array('controller' => 'friends', 'action' => 'follow'), 
				array(
					'method' => 'POST',
					'data' => 'data[Friend][following]='.$user_id,
					'error' => 'error()',
					'success' => 'successFollowing(data, "#follow_action")',
					'type' => 'json', 
					'escape' => false,
                                        'class' => 'button',
                                        'title' => sprintf(__('Follow %s', true), $username),
                                        
				)
			);
		}
	}

	public function unfollow($friend_id, $username){

		return $this->Js->link(
			$this->Html->tag('span', __('Unfollow', true)),
			array('controller' => 'friends', 'action' => 'unfollow'),
			array(
				'method' => 'POST',
				'data' => 'data[Friend][following]='.$friend_id,
				'error' => 'error()',
				'success' => 'successUnfollow(data)',
				'type' => 'json',
				'escape' => false,
                                'class' => 'button',
                                'title' => sprintf(__('Unfollow %s', true), $username),
                                
			)
		);
	
	}
}
?>